package com.dwms.controller;


import com.dwms.entity.*;
import com.dwms.entity.system.menu.response.MenuResponse;
import com.dwms.entity.system.role.request.RoleQueryRequest;
import com.dwms.entity.system.role.request.RoleRequest;
import com.dwms.entity.system.role.response.RoleResponse;
import com.dwms.feign.system.RoleFeignClient;
import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: RoleMapper
 * @Description: Role
 * @Create 2022/03/05 20:47
 * @Author WH
 * @Since 2.0.0
**/
@Tag(name = "角色管理")
@RestController(value = "RoleController")
@RequestMapping(value = "/system/role")
@RequiredArgsConstructor
public class RoleController {
    private final HttpServletRequest request;
    private final RoleFeignClient roleFeignClient;

    @Operation(summary = "新增角色")
    @PostMapping("/save")
    public Result save(@RequestBody RoleRequest roleRequest) {
        WebUtil.getAdminRequest(request,roleRequest);
        return roleFeignClient.save(roleRequest);
    }

    @Operation(summary = "修改角色")
    @PostMapping("/update")
    public Result update(@RequestBody RoleRequest roleRequest) {
        WebUtil.getAdminRequest(request,roleRequest);
        return roleFeignClient.update(roleRequest);
    }

    @Operation(summary = "分页查询角色")
    @PostMapping("/findPage")
    public Result<PageResponse<RoleResponse>> findPage(@RequestBody RoleQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return roleFeignClient.findPage(query);
    }

    @Operation(summary = "根据ID查询角色")
    @PostMapping("/findById")
    public Result findById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return roleFeignClient.findById(query);
    }

    @Operation(summary = "删除角色")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return roleFeignClient.delete(query);
    }

    @Operation(summary = "根据角色查询菜单")
    @PostMapping("/findMenuByRoleId")
    public Result<List<MenuResponse>> findMenuByRoleId(@RequestBody QueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return roleFeignClient.findMenuByRoleId(query);
    }

    @Operation(summary = "角色列表查询")
    @PostMapping("/findList")
    public Result<List<RoleResponse>> findList() {
        Request requestVO = new Request();
        WebUtil.getAdminRequest(request,requestVO);
        return roleFeignClient.findList(requestVO);
    }

    @Operation(summary = "修改状态")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody QueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return roleFeignClient.updateStatus(query);
    }
}
